/*
 * Main.fx
 *
 * Created on Mar 2, 2009, 1:35:29 PM
 */

package hlequaliser;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Line;
import javafx.scene.paint.*;
import javafx.scene.shape.Path;
import javafx.scene.input.MouseEvent;
import javafx.scene.Group;


/**
 * @author forsakendaemon
 */
var x: Number = 220;
var y: Number = 200;
var xStep: Number = 10;
var yStep: Number = 9;
var leftValues: Number[] = [50,40,0,10,-10,70,90,90];
var rightValues: Number[] = [0,0,0,0,0,0,0,0];
def freqs: Number[] = [250, 500, 1000, 2000, 3000, 4000, 6000, 8000];
var rightSelected: Boolean = true;
var rightMarks: Right[] = bind for (right in rightValues)
    Right {
        x: ((indexof right + 1) * y / yStep + 50);
        y: ((right + 10) * 0.1 * x / xStep + 50);
    };
var leftMarks: Left[] = bind for (left in leftValues)
    Left {
        x: ((indexof left + 1) * y / yStep + 50);
        y: ((left + 10) * 0.1 * x / xStep + 50);
    };


        Stage {
    title: "HREqualiser",
    width: 500,
    height: 350,
    scene:
            Scene {
                content: [
                    Rectangle {
                        x: 50,
                        y: 50,
                        width: y,
                        height: x,
                        fill: Color.WHITE,
                        stroke: Color.BLACK
                        onMouseClicked: function(event: MouseEvent):Void {
                            var xOffset = (event.x * xStep / x - 3) as Integer;
                            var yOffset = (event.y * yStep / y - 3) as Integer;
                            yOffset = yOffset * 10;
                            //println("Clicked! x: {xOffset}, y: {yOffset}");
                            if (rightSelected) {
                                delete rightValues[xOffset]; insert yOffset before rightValues[xOffset];
                            } else {
                                delete leftValues[xOffset]; insert yOffset before leftValues[xOffset];
                            };
                        }
                    },
            for (i in [1..10]) {
                        Line {
                            startX: 50,
                            endX: 250,
                            startY: (i * x / xStep + 50),
                            endY: (i * x / xStep + 50),
                        }
                    },
            for (j in [1..8]) {
                        Line {
                            startX: (j * y / yStep + 50),
                            endX: (j * y / yStep + 50),
                            startY: 50,
                            endY: 270,
                            strokeDashArray: (if (j mod 2 == 1) then [2.0, 4.0] else [1.0]),
                        }
                    },
                    Rectangle {
                        x: 300,
                        y: 100,
                        width: 100,
                        height: 100,
                        fill: Color.WHITE,
                        stroke: Color.BLACK,
                        onMouseClicked: function(event:MouseEvent) {
                            rightSelected = (if (event.y < 150) then true else false);
                        }
                    },
                    Right {
                        x: 325,
                        y: 125,
                    },
                    Left {
                        x: 325,
                        y: 175,
                    },
                    Group {
                        content: bind [
                        rightMarks,
                        leftMarks,
                        ]
                    },




                ]
            }
        }
